package com.zadtek.jpsqishi.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.zadtek.jpsqishi.R;
import com.zadtek.jpsqishi.activity.common.Common;

/**
 * 我的统计
 * @author kuyukeji
 *
 */
public class MytjFragment extends FragmentActivity{

	private ImageView backid;
	private TextView topview, rightname; // 标题,右边的标题

	private RadioGroup radioGroup;
	private FragmentTransaction fragmentTrans;

	private MytjChildFragment fragment;	//我的统计

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragment_mytj);
		
		backid = (ImageView) findViewById(R.id.backid);
		backid.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		topview = (TextView) findViewById(R.id.topview);
		topview.setText("我的统计");
		rightname = (TextView) findViewById(R.id.rightname);
		rightname.setVisibility(View.VISIBLE);
		rightname.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent paih = new Intent(MytjFragment.this, PaihFragment.class);
				startActivity(paih);
			}
		});

		radioGroup = (RadioGroup) findViewById(R.id.tab_radio);
		
		fragmentTrans = getSupportFragmentManager().beginTransaction();
		if (fragment == null) {	//默认显示第一个
			fragment = new MytjChildFragment();   
			fragmentTrans.add(R.id.layout_content, fragment).commit();
        }

		radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.radio_all: // 昨天
					fragment = new MytjChildFragment();
					String time1 = Common.getLastDay();
					fragment.setTime(time1);
					getSupportFragmentManager().beginTransaction()
							.replace(R.id.layout_content, fragment).commit();
					break;
					
				case R.id.radio_today:	//今天
					fragment = new MytjChildFragment();
					String timejt = Common.getToday();
					fragment.setTime(timejt);
					getSupportFragmentManager().beginTransaction()
							.replace(R.id.layout_content, fragment).commit();
					break;
				case R.id.radio_nopay: // 本月
					fragment = new MytjChildFragment();
					String time = Common.getCurrMonth();
					fragment.setTime(time);
					getSupportFragmentManager().beginTransaction()
							.replace(R.id.layout_content, fragment).commit();
					break;
					
				case R.id.radio_payed: // 上月
					fragment = new MytjChildFragment();
					String time3 = Common.getLastMonth();
					fragment.setTime(time3);
					getSupportFragmentManager().beginTransaction()
							.replace(R.id.layout_content, fragment).commit();
					break;
				}
			}
		});
	}

}
